<template>
  <!-- 查询条件：部门名称 部门类型 部门状态 -->
  <el-form :model="form" label-width="auto" :inline="true">
    <!-- 部门名称 -->
    <el-form-item label="部门名称：">
      <el-input v-model="form.departmentName" />
    </el-form-item>
    <!-- 部门类型 -->
    <el-form-item label="部门类型">
      <el-select v-model="form.departmentTypeId" placeholder="请选择所属类别" style="width: 200px;">
        <el-option v-for="item in typeData" :label="item.departmentTypeName" :value="item.departmentTypeId" />
      </el-select>
    </el-form-item>
    <!-- 按钮 查询 导出部门信息 -->
    <el-form-item>
      <el-button type="danger" @click="getDepartmentList">查询</el-button>
      <el-button type="danger">导出部门信息</el-button>
    </el-form-item>
  </el-form>

  <!-- 显示数据 -->
  <el-table :data="departmentList" style="width: 100%">
    <el-table-column prop="departmentId" label="部门编号" />
    <el-table-column prop="departmentName" label="部门名称" />
    <el-table-column prop="departmentTypeName" label="部门类型" />
    <el-table-column prop="name" label="级别" />
    <el-table-column prop="directSuperior" label="部门全称" />
    <el-table-column prop="directSuperiorName" label="部门主管" />
    <el-table-column prop="inChargeHead" label="财务主管" />
    <el-table-column prop="name" label="操作人">
      <template #default="scope">
        <span>罗Sir</span>
      </template>
    </el-table-column>
    <el-table-column prop="address" label="操作时间" />
  </el-table>

  <!-- 分页 -->
  <table>
    <tr>
      <!-- 1. -->
      <td>
        <el-pagination v-model:current-page="form.Pindex" v-model:page-size="form.Psize" :page-sizes="[1, 3, 5, 7]"
          :size="form.Psize" :background="true" layout="total,slot, sizes" :total="form.totalCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          数据，每页显示{{ form.Psize }}条数据，当前第1/{{
            form.Pindex
          }}页，共{{ form.pageCount }}页。
        </el-pagination>
      </td>
      <!-- 2. -->
      <td>
        <el-pagination v-model:current-page="form.Pindex" v-model:page-size="form.Psize" :page-sizes="[1, 3, 5, 7]"
          :size="form.pageSize" :background="true" layout="slot,prev, pager" :total="form.totalCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <el-button @click="handleCurrentChange(1)">首页</el-button>
        </el-pagination>
      </td>
      <!-- 3. -->
      <td>
        <el-pagination v-model:current-page="form.Pindex" v-model:page-size="form.Psize" :page-sizes="[1, 3, 5, 7]"
          :size="form.pageSize" :background="true" layout="next,slot, jumper" :total="form.totalCount" prev-text="上一页"
          next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <el-button @click="handleCurrentChange(form.pageCount)">尾页</el-button>
        </el-pagination>
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from "vue";
import axios from "axios";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
//生命周期 钩子函数
onMounted(() => {
  getDepartmentList(); //部门设置-显示
});

//定义变量
const form = reactive({
  departmentName: '',
  departmentTypeId: '',
  departmentIsNot: '',
  pageSize: 5,
  Pindex: 1,
  Psize: 2,
  totalCount: 0,
  pageCount: 0,
});

//部门设置-显示
const departmentList = ref([]);
const getDepartmentList = () => {
  axios
    .get("http://localhost:5039/api/Depart/GetDepartment", {
      params: {
        Pindex: form.Pindex,
        Psize: form.Psize
      }
    })
    .then((res) => {
      console.log(res);
      departmentList.value = res.data.data;
      form.pageCount = res.data.totalPage;
      form.totalCount = res.data.totalCount;
    })
    .catch((err) => {
      console.log(err);
    });
};
//分页
const handleSizeChange = (val: number) => {
  form.Psize = val;
  getDepartmentList();
};
const handleCurrentChange = (val: number) => {
  form.Pindex = val;
  getDepartmentList();
};

//部门类型下拉框
const typeData: any = ref([])
const getFunctionData = () => {
  axios.get('http://localhost:5039/api/Depart/SearchDepartType').then(res => {
    console.log(res)
    typeData.value = res.data.data
  })
}
onMounted(() => {
  getFunctionData()
  getDepartmentList();
})

</script>
